// Messen der Ausgangsspannungen des Rigol DP831 Power Supply mit dem Tonghui TH1951 DMM.
// Die Messwerte werden als CSV-Datei gespeichert, und knnen mit z.B. Excel geffnet werden.

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Die Instrumente verbinden.
instrument $TH serial com4 // Tonghui TH1951 5 1/2 Digit Multimeter, Standardwerte 9600 8 1 none none.
instrument $DP usbtmc 1AB1 0E11 // Rigol DP831 Linear DC Power Supply.

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Konstanten und Variablen erstellen.
#FileName set "E:\Rigol DP831 Ausgang Spannung.csv" // Die Anfhrungszeichen bleiben erhalten.
#ChannelCount set 3
#Channel1MaxVolt set 8.1
#Channel2MaxVolt set 32.1
#Channel3MaxVolt set -32.1
#Step set 0.5
#WaitStep set 2000
#Separator set ;
integer Counter
integer Channel
float Level
string Measurement
float ReadDP
float ReadTH

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Die CSV-Datei vorbereiten.
Measurement set Ausgang 1
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt TH1951
Measurement function save #FileName eol

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// TH1951 vorbereiten.
$TH // Das Instrument auswhlen.
#WaitRead set 600
function scpi write *RST
function wait 2000
function scpi write :TRIG:SOUR BUS
function scpi write :TRIG:COUN 10
function scpi write :SENS:VOLT:DC:NPLC 10
function scpi write :CONF:VOLT:DC
function wait 1000
function scpi write :SENSE:VOLT:DC:RANG 10

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// DP800 vorbereiten.
$DP // Das Instrument auswhlen.
function scpi write *RST
function wait 1000
// Den Lfter drosseln auf den kleinsten Wert der erlaubt ist.
// Das muss vor dem Aktivieren der Ausgnge geschehen.
function scpi write :PROJect:FAN 30

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Bei allen Ausgngen die Spannung- und Stromberwachung auf
// die gewnschten Werte setzen und die berwachung aktivieren.
Channel set 1
label ProtectionMax
function scpi write :SOUR$Channel:VOLT:PROT:LEV MAX
function scpi write :SOUR$Channel:VOLT:PROT:STAT ON
function scpi write :SOUR$Channel:CURR:PROT:LEV 0.5
function scpi write :SOUR$Channel:CURR:PROT:STAT ON
Channel add 1
Channel greater #ChannelCount
false goto ProtectionMax

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Alle Ausgnge vorbereiten.
Level set 0.5
Channel set 1
label OutputInit
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :SOUR$Channel:CURR $Level
Channel add 1
Channel greater #ChannelCount
false goto OutputInit

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 1.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 1 verbinden.

// Ausgang 1 aktivieren und die Spannung schrittweise erhhen.
Counter set 1
Channel set 1
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output1Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$TH
function scpi write *TRG
function wait #WaitRead
ReadTH function scpi read :FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadTH
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level add #Step
Level less #Channel1MaxVolt
true goto Output1Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 2.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 2 verbinden.

// Die CSV-Datei vorbereiten.
Measurement set $eol
Measurement add Ausgang 2
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt TH1951
Measurement function save add #FileName eol

// TH1951 vorbereiten.
$TH
function scpi write :SENSE:VOLT:DC:RANG 100

// Ausgang 2 aktivieren und die Spannung schrittweise erhhen.
$DP
Counter set 1
Channel set 2
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output2Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$TH
function scpi write *TRG
function wait #WaitRead
ReadTH function scpi read :FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadTH
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level add #Step
Level less #Channel2MaxVolt
true goto Output2Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 3.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 3 verbinden.

// Die CSV-Datei vorbereiten.
Measurement set $eol
Measurement add Ausgang 3
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt TH1951
Measurement function save add #FileName eol

// Ausgang 3 aktivieren und die Spannung schrittweise erhhen.
Counter set 1
Channel set 3
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output3Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$TH
function scpi write *TRG
function wait #WaitRead
ReadTH function scpi read :FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadTH
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level sub #Step // Negative Spannung.
Level greater #Channel3MaxVolt // Negative Spannung.
true goto Output3Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF
function scpi write :SYSTem:LOCal

// Ende.
function beep information
